from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime

class CEPRequest(BaseModel):
    trans_code: str = Field(default="CEP", description="交易代码")
    appid: str = Field(max_length=3, description="交易来源")
    pan: str = Field(max_length=19, description="卡号")
    orderid: str = Field(max_length=30, description="订单流水")
    trans_date: str = Field(max_length=8, description="交易日期")
    trans_time: str = Field(max_length=6, description="交易时间")
    trans_amt: str = Field(max_length=12, description="交易金额（分）")
    merno: str = Field(max_length=15, description="商户号")
    terminal: str = Field(max_length=8, description="终端号")
    cur_code: str = Field(default="156", max_length=3, description="货币代码")
    pay_order: str = Field(max_length=20, description="外部订单号")
    pay_merchant: Optional[str] = Field(None, max_length=20, description="外部商户号")
    pay_mername: Optional[str] = Field(None, max_length=120, description="外部商户名")
    rrn: Optional[str] = Field(None, max_length=12, description="POSP参考号")
    md5: Optional[str] = Field(None, description="大写MD5值")

    class Config:
        json_schema_extra = {
            "example": {
                "appid": "01",
                "pan": "2168890010126843",
                "trans_amt": "000000001000",
                "pay_order": "TEST202507100001",
                "merno": "999999999999997",
                "terminal": "99999996"
            }
        }

class CEPResponse(BaseModel):
    trans_code: str = Field(default="CEP", description="交易代码")
    bank_date: str = Field(max_length=8, description="清算日期")
    resp_code: str = Field(max_length=5, description="响应码")
    trans_sn: str = Field(max_length=30, description="卡系统流水号")
    rrn: str = Field(max_length=12, description="卡系统参考号")
    orderid: str = Field(max_length=30, description="请求订单流水")
    pan: str = Field(max_length=19, description="卡号")
    balance: Optional[str] = Field(None, min_length=12, description="账户卡余额")
    md5: Optional[str] = Field(None, description="大写MD5值")
    error_msg: Optional[str] = Field(None, description="错误信息") 